﻿using System;
using Caliburn.Micro;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Wulong.Phone.Qiushi.i18n;

namespace Wulong.Phone.Qiushi.Views
{
    public partial class PicView
    {
        double initialAngle;
        double initialScale;
        public PicView()
        {
            InitializeComponent();
            transform.ScaleX = transform.ScaleY =1;
            transform.Rotation = 0;
            LoadAppBar();
        }

        private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
        {
            initialAngle = transform.Rotation;
            initialScale = transform.ScaleX; 
        }

        private void OnPinchDelta(object sender, PinchGestureEventArgs e)
        {
            transform.Rotation = initialAngle + e.TotalAngleDelta;
            transform.ScaleX = initialScale * e.DistanceRatio;
            transform.ScaleY = initialScale * e.DistanceRatio; 
        }

        private void OnDragDelta(object sender, DragDeltaGestureEventArgs e)
        {
            transform.TranslateX += e.HorizontalChange;
            transform.TranslateY += e.VerticalChange;
        }

        private void LoadAppBar()
        {
            // Set the page's ApplicationBar to a new instance of ApplicationBar
            ApplicationBar = new ApplicationBar();
            var doneButton = new AppBarButton
            {
                IconUri = new Uri("/Toolkit.Content/ApplicationBar.Check.png", UriKind.Relative),
                Text = AppResources.V_Pic_Back_Button,
                Message = "GoBack"
            };
            ApplicationBar.Buttons.Add(doneButton);

        }
    }
}
